<?php

namespace App\Http\Controllers;

use App\Http\Common\Consumer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class AdminController extends Controller
{
    /**
     * 设置自定义菜单
     */
    public function wx_menu(){
        $Comsumer = new Consumer();
        $access_token = $Comsumer->getWxAccessToken();

        //创建微信菜单
        $url ='https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$access_token;
        $postArr = array(
            'button'=>array(//第一个一级菜单
                array(
                    'name'=>urlencode('科学洗涤'),
                    'sub_button'=>array(
                        array(
                            'name'=>urlencode('清洁难题'),
                            'type'=>'view',
                            'url'=>'https://bi.bluemoon.com.cn'
                        ),
                        array(
                            'name'=>urlencode('产品用法'),
                            'type'=>'view',
                            'url'=>'https://bi.bluemoon.com.cn'
                        ),
                        array(
                            'name'=>urlencode('售后指引'),
                            'type'=>'view',
                            'url'=>'https://bi.bluemoon.com.cn'
                        )
                    )
                ),
                array(//第二个一级菜单
                    'name'=>urlencode('服务中心'),
                    'sub_button'=>array(
                        array(
                            'name'=>urlencode('物流查询'),
                            'type'=>'view',
                            'url'=>'https://bi.bluemoon.com.cn/consumerServer/queryLogistics.html'
                        ),
                        array(
                            'name'=>urlencode('在线客服'),
                            'type'=>'view',
                            'url'=>'https://bi.bluemoon.com.cn'
                        )
                    )
                ),
                array(//第三个一级菜单
                    'name'=>urlencode('个人尊享'),
                    'sub_button'=>array(
                        array(
                            'name'=>urlencode('我的顾问'),
                            'type'=>'view',
                            'url'=>'https://bi.bluemoon.com.cn/consumerServer/myConsult.html'
                        ),
                        array(
                            'name'=>urlencode('注册登录'),
                            'type'=>'view',
                            'url'=>'https://bi.bluemoon.com.cn/consumerServer/login.html'
                        ),
                        array(
                            'name'=>urlencode('个人中心'),
                            'type'=>'view',
                            'url'=>'https://bi.bluemoon.com.cn/consumerServer/myPage.html'
                        )
                    )
                )
            )
        );
        $postJson = urldecode(json_encode($postArr,true));
        $res = curl_post($url,$postJson);
        var_dump($res);//查看上传自定义菜单的返回结果
    }
}
